package com.itheima.api.stream.demo06;

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo01 {

    public static void main(String[] args) {

        ArrayList<Integer> arrayList = new ArrayList<Integer>();

        arrayList.add(23);
        arrayList.add(12);
        arrayList.add(34);
        arrayList.add(56);
        arrayList.add(33);
        arrayList.add(56);

        Stream<Integer> stream = arrayList.stream().filter(s -> s >= 34);

//        List<Integer> collect = stream.collect(Collectors.toList());
//        collect.forEach(s -> System.out.println(s));

        System.out.println("---------------------------------------------------------");

        Set<Integer> set = stream.collect(Collectors.toSet());
        set.forEach(s -> System.out.println(s));

        System.out.println("---------------------------------------------------------");

        ArrayList<String> arrayList1 = new ArrayList<String>();

        arrayList1.add("张三,23");
        arrayList1.add("李四,24");
        arrayList1.add("王五,20");
        arrayList1.add("赵六,36");

        Stream<String> stringStream = arrayList1.stream().filter(s -> {

            String[] split = s.split(",");
            String ageStr = split[1];

            int age = Integer.parseInt(ageStr);

            if (age >= 23) {
                return true;
            } else {
                return false;
            }

        });

        System.out.println("------------------------------------------------------");

        Map<String, Integer> collect = stringStream.collect(Collectors.toMap((s) -> {
            String[] info = s.split(",");
            return info[0];
        }, (s) -> {
            String[] info = s.split(",");
            return Integer.parseInt(info[1]);
        }));

        collect.forEach((key, value) -> System.out.println(key + "----" + value));

    }

}
